package cn.unknowpupil.init.controller.quartz;


import cn.unknowpupil.init.common.enums.BusinessType;
import cn.unknowpupil.init.common.resopnse.ResultResponse;
import cn.unknowpupil.init.components.annotation.Log;
import cn.unknowpupil.init.domain.system.SysJobLog;
import cn.unknowpupil.init.service.system.ISysJobLogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created at 2020-11-06 by  w10g <br>
 * Initialize SysJobLog  ... <br>
 *  定时任务调度日志表 视图浏览层处理
 *
 * @author unknowpupil
 * @since 0.0.1
 */

@Api(tags = {"系统-定时任务调度日志表模块" }, value = "SysJobLog")
@RestController
@RequestMapping(value = "admin/sys-job-log")
public class SysJobLogController {
    @Autowired
    private  ISysJobLogService sysJobLogService;


    /**
     * 删除
     *
     * @param ids {@code Long}
     * @return {@link ResultResponse}
     */
    @ApiOperation("系统：删除定时任务调度日志表")
    @Log(title = "删除定时任务调度日志表", businessType = BusinessType.DELETE)
    @DeleteMapping("remove/{ids}")
    public ResultResponse remove(@PathVariable("ids") Long[] ids) {
        // 业务逻辑
        boolean deleted  = sysJobLogService.deleteJobLogByIds(ids);
        if(deleted){
            return ResultResponse.success("删除成功");
        }else{
            return ResultResponse.buildFailure("删除失败");
        }
    }

    /**
     * 分页
     *
     * @param current {@code int} 页码
     * @param size    {@code int} 笔数
     * @return {@link ResultResponse}
     */
    @ApiOperation("系统：分页定时任务调度日志表")
    @GetMapping("page/{current}/{size}")
    public ResultResponse<IPage<SysJobLog>> page(@PathVariable("current") int current, @PathVariable("size") int size, @ModelAttribute SysJobLog sysJobLog) {
        IPage<SysJobLog> page = sysJobLogService.page(current, size, sysJobLog);
        return ResultResponse.buildSuccess(page);
    }




    /**
     * 清空定时任务调度日志
     */
    @ApiOperation("系统：清空定时任务调度日志")
    @Log(title = "清空定时任务调度日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public ResultResponse clean()
    {
        sysJobLogService.cleanJobLog();
        return ResultResponse.success("清空定时任务成功");
    }
}
